<?php

/**
 * Filter Model - Database functions related to item, item type, brand, brand model, etc..
 * 
 * @project : Loobica
 * @author  : Dino
 * @date    : 08 Mar 2014
 * 
 */
class Filter_model extends CI_Model {

  function __construct() {
    parent::__construct();
  }

  /**
   * Get items in a category
   * 
   * @param type $category_id
   * @return type
   */
  function get_items($category_id = 0) {
    return $this->db->select('*')
                    ->where('item_category_id', (int) $category_id)
                    ->get('item')
                    ->result_array();
  }

  /**
   * Get item types of an item
   * 
   * @param type $category_id
   * @return type
   */
  function get_item_types($category_id = array()) {
    return $this->db->select('item_type.*')
                    ->join('item', 'item_id = item_relation_item_id')
                    ->join('item_type', 'item_type_id = item_relation_item_type_id')
                    ->where('item_category_id', (int) $category_id)
                    ->group_by('item_type_id')
                    ->get('item_relation')
                    ->result_array();
  }

  /**
   * Get item extras
   * 
   * @param type $item_ids
   * @return type
   */
  function get_item_extras($item_ids = array()) {
    $item_ids = (!empty($item_ids) && is_array($item_ids)) ? $item_ids : array(0);
    return $this->db->select('item_extra.*')
                    ->join('item', 'item_id = item_relation_extra_item_id')
                    ->join('item_extra', 'item_extra_id = item_relation_extra_item_extra_id')
                    ->where_in('item_id', $item_ids)
                    ->group_by('item_extra_id')
                    ->get('item_relation_extra')
                    ->result_array();
  }

  /**
   * Get brands
   * 
   * @param type $category_id
   * @return type
   */
  function get_brands($category_id = 0) {
    return $this->db->select('*')
                    ->where('brand_category_id', (int) $category_id)
                    ->get('brand')
                    ->result_array();
  }

  /**
   * Get brand models
   * 
   * @param type $category_id
   * @return type
   */
  function get_brand_models($category_id = array()) {
    return $this->db->select('brand_model.*')
                    ->join('brand', 'brand_id = brand_model_brand_id')
                    ->where('brand_category_id', (int) $category_id)
                    ->get('brand_model')
                    ->result_array();
  }

  /**
   * Get price ranges
   * 
   * @return type
   */
  function get_price_ranges() {
    return array(
        array('price_range_id' => 1, 'price_range_min' => 0, 'price_range_max' => 500, 'price_range_text' => 'Below 500'),
        array('price_range_id' => 2, 'price_range_min' => 501, 'price_range_max' => 1000, 'price_range_text' => '501 to 1000'),
        array('price_range_id' => 3, 'price_range_min' => 1001, 'price_range_max' => 10000, 'price_range_text' => '1001 to 10000'),
        array('price_range_id' => 4, 'price_range_min' => 10001, 'price_range_max' => 25000, 'price_range_text' => '10001 to 25000'),
        array('price_range_id' => 5, 'price_range_min' => 25001, 'price_range_max' => 50000, 'price_range_text' => '25001 to 50000'),
        array('price_range_id' => 6, 'price_range_min' => 50001, 'price_range_max' => 100000, 'price_range_text' => '50001 to 1 Lakh'),
        array('price_range_id' => 7, 'price_range_min' => 100001, 'price_range_max' => 500000, 'price_range_text' => '1 Lakh to 5 Lakhs'),
        array('price_range_id' => 8, 'price_range_min' => 500001, 'price_range_max' => 1000000, 'price_range_text' => '5 Lakhs to 10 Lakhs'),
        array('price_range_id' => 9, 'price_range_min' => 1000001, 'price_range_max' => 5000000, 'price_range_text' => '10 Lakhs to 50 Lakhs'),
        array('price_range_id' => 10, 'price_range_min' => 5000001, 'price_range_max' => 10000000, 'price_range_text' => '50 Lakhs to 1 crore'),
        array('price_range_id' => 11, 'price_range_min' => 10000001, 'price_range_max' => 0, 'price_range_text' => 'Above 1 crore'),
    );
  }

  /**
   * Get give for
   * 
   * @return type
   */
  function get_give_for() {
    return array(
        array('give_for_id' => 1, 'give_for_text' => 'Buy'),
        array('give_for_id' => 2, 'give_for_text' => 'Rent'),
        array('give_for_id' => 3, 'give_for_text' => 'Lease'),
    );
  }

  /**
   * Get peoples
   * 
   * @return type
   */
  function get_peoples() {
    return array(
        array('people_id' => 1, 'people_text' => 'Gents'),
        array('people_id' => 2, 'people_text' => 'Ladies'),
        array('people_id' => 3, 'people_text' => 'Couples'),
        array('people_id' => 4, 'people_text' => 'Family'),
        array('people_id' => 5, 'people_text' => 'Bachelors'),
        array('people_id' => 6, 'people_text' => 'Bachelorettes'),
        array('people_id' => 7, 'people_text' => 'Students'),
        array('people_id' => 8, 'people_text' => 'Employees'),
        array('people_id' => 9, 'people_text' => 'Married Mens'),
        array('people_id' => 10, 'people_text' => 'Married Womens')
    );
  }

}

?>